/**
 * @description 应用配置
*/

/* 运行模式配置 */
(function () {
  const origin = location.origin
  const domain = /file:/.test(location.protocol) ? '//127.0.0.1' : location.origin
  const domainname = /file:/.test(location.protocol) ? '//127.0.0.1' : location.protocol + '//' + location.hostname

  // 开发环境配置
  const dev = {
    mode: 'dev',
    title: '开发模式',
    // 服务匹配规则列表
    rules: [
      {rule: 'host', url: domainname + ':8100'},
      {rule: 'pot', url: 'foundation'}
    ],
    // 环境域名
    domain,
    // 模块加载器
    loader: {
      path: domain + '/pool/prod/packages/@daelui/pigjs/latest/dist/system.min.js',
      registry: domain + '/pool/prod/packages.json',
      rootUrl: domain + '/pool/prod/packages'
    },
    cesium: {
      options: {
        showRenderLoopErrors: true
      },
      CESIUM_BASE_URL: /daelui\.com/i.test(location.host) ? 'https://unpkg.com/cesium@1.95.0/Build/Cesium' :
      /daelui\.cn/i.test(location.host) || /#\/dmapt/i.test(location.href) ? origin + '/pool/prod/packages/cesium/1.95.0/Build/Cesium' :
        /file:/i.test(location.protocol) ? (origin + location.pathname).replace(/\w+\.\w+$/i, '') + '/assets/Cesium' :
        /\/app/i.test(location.pathname) ? '/app/assets/Cesium' : '/assets/Cesium'
    }
  }

  // 生产环境配置
  const prod = {
    mode: 'prod',
    title: '生产模式',
    // 服务匹配规则列表
    rules: [
      {rule: 'host', url: domainname + ':8100'},
      {rule: 'pot', url: 'foundation'}
    ],
    // 环境域名
    domain,
    // 模块加载器
    loader: {
      path: domain + '/pool/prod/packages/@daelui/pigjs/latest/dist/system.min.js',
      registry: domain + '/pool/prod/packages.json',
      rootUrl: domain + '/pool/prod/packages'
    },
    cesium: {
      options: {
        showRenderLoopErrors: false
      },
      CESIUM_BASE_URL: /daelui\.com/i.test(location.host) ? 'https://unpkg.com/cesium@1.95.0/Build/Cesium' :
        /daelui\.cn/i.test(location.host) || /#\/dmapt/i.test(location.href) ? origin + '/pool/prod/packages/cesium/1.95.0/Build/Cesium' :
        /file:/i.test(location.protocol) ? (origin + location.pathname).replace(/\w+\.\w+$/i, '') + '/assets/Cesium' :
        /\/app/i.test(location.pathname) ? '/app/assets/Cesium' : '/assets/Cesium'
    }
  }

  /* 应用配置 */
  const application = {
    dev, prod,
    // 运行模式配置
    mode: {dev, prod}.prod
  }

  window.application = window.application || {}
  window.application.dmapt = application
})();